<?php

final class GerenciaHelpdesk{
	private $sqlHelpdesk;
	private $resultHelpdesk;
	private $objectHelpdesk;
	private $conexao;
	private $parametro;
	
	public function __construct(ConectaMysql $conexao){		
		$this->conexao = $conexao;
	}
	
	
	public function insertHelpdesk(Helpdesk $objectHelpdesk){
        $this->objectHelpdesk = $objectHelpdesk;
        
		$this->sqlHelpdesk = "INSERT INTO tb_helpdesk(`HELPtitulo`,`HELPconteudo`,`HELP_CATid`,`HELP_FUNid`,`HELP_DEST_SETid`) VALUES (
							'".($this->objectHelpdesk->getHELPtitulo())."',
							'".($this->objectHelpdesk->getHELPconteudo())."',
							'".($this->objectHelpdesk->getCATid())."',
							'".($this->objectHelpdesk->getFuncionarioId())."',
							'".($this->objectHelpdesk->getSetorId())."')";
		
		$this->conexao->executaQuery($this->sqlHelpdesk);

	}
	
	public function selectMaxId(){
		
		$this->sqlHelpdesk = "SELECT MAX(HELPid) as HELPid FROM tb_helpdesk";	
		$this->resultHelpdesk  = $this->conexao->executaQuery($this->sqlHelpdesk);
		return $this->resultHelpdesk;
	}
	
	public function selectHelpdesk($parametro = false){
		
		$this->parametro = $parametro;
		$this->sqlHelpdesk = "SELECT		
							tb_helpdesk.HELPid, 
							tb_helpdesk.HELPtitulo,
							tb_helpdesk.HELPconteudo,
							tb_helpdesk.HELP_DEST_SETid,
							tb_categoria.CATid,
							tb_categoria.CATdescricao,
							tb_funcionario.FUNid,
							tb_funcionario.FUNnome,
							tb_funcionario.FUNsobrenome,
							tb_setor.SETid,
							tb_setor.SETsigla,
							tb_setor.SETnome,
							tb_gestao.GESTdatainicial,
							tb_situacao.SITid,
							tb_situacao.SITdescricao
						
							FROM  tb_helpdesk
						
							INNER JOIN tb_categoria ON
							tb_helpdesk.HELP_CATid = tb_categoria.CATid
							
							INNER JOIN tb_gestao ON
							tb_helpdesk.HELPid = tb_gestao.GEST_HELPid
							
							INNER JOIN tb_situacao ON
							tb_gestao.GEST_SITid = tb_situacao.SITid
							
							INNER JOIN tb_funcionario ON
							tb_helpdesk.HELP_FUNid = tb_funcionario.FUNid
							
							INNER JOIN tb_acesso ON
							tb_acesso.ACE_FUNid = tb_funcionario.FUNid
							
							INNER JOIN tb_privilegio ON
							tb_privilegio.PRIVid = tb_acesso.ACE_PRIVid
							
							INNER JOIN tb_setor ON
							tb_funcionario.FUN_SETid = tb_setor.SETid";
								
		if($this->parametro){	
		
			$this->sqlHelpdesk = $this->sqlHelpdesk." WHERE tb_helpdesk.HELPid = '".$this->parametro."'";
			
			
		}
		
		$this->resultHelpdesk  = $this->conexao->executaQuery($this->sqlHelpdesk);
		return $this->resultHelpdesk;

	}
	
	
	
	public function updateHelpdesk(Helpdesk $objectHelpdesk){
        $this->objectHelpdesk = $objectHelpdesk;
        
		$this->sqlHelpdesk = "UPDATE tb_helpdesk
		
							  SET HELPtitulo = '".($this->objectHelpdesk->getHELPtitulo())."',
							  	  HELPconteudo = '".($this->objectHelpdesk->getHELPconteudo())."',
								  HELP_CATid = '".($this->objectHelpdesk->getCATid())."',
								  HELP_FUNid = '".($this->objectHelpdesk->getFuncionarioId())."',
								  HELP_DEST_SETid = '".($this->objectHelpdesk->getSetorId())."'
							  WHERE HELPid = '".($this->objectHelpdesk->getHELPid())."'";
							  
		$this->conexao->executaQuery($this->sqlHelpdesk);
											  
	}
	
	
	public function quantHelpdesk($situacao = false, $categoria = false, $setor = false){
		
		$this->situacao  =  addslashes($situacao);
		$this->categoria =  addslashes($categoria);
		$this->setor =  addslashes($setor);
		
		$this->sqlHelpdesk = "SELECT count(tb_helpdesk.HELPid) as `quantHelpdesk`		
							
							FROM tb_helpdesk 
														
							INNER JOIN tb_gestao ON
							tb_gestao.GEST_HELPid = tb_helpdesk.HELPid
							
							INNER JOIN tb_situacao ON
							tb_situacao.SITid = tb_gestao.GEST_SITid
							
							WHERE (tb_helpdesk.HELPstatus = '1')";
							
		if($this->situacao){						
			$this->sqlHelpdesk." AND (tb_situacao.SITid = '".$this->parametro."')";					
							 
		}
		if($this->categoria){
			$this->sqlHelpdesk." AND (tb_categoria.CATid = '".$this->parametro."')";
			
		}
		
		if($this-setor){
			$this->sqlHelpdesk." AND (tb_helpdesk.HELP_DEST_SETid = '".$this->setor."')";
			
		}
		
		$this->resultHelpdesk = $this->conexao->executaQuery($this->sqlHelpdesk);
		return $this->resultHelpdesk;
		
	}
	
}
	
?>